package Dungeon;

import static org.junit.Assert.*;

import java.math.BigDecimal;
import java.util.HashMap;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import SquarePackage.NormalSquare;
import SquarePackage.Square;

public class RoomTest {
	
	private NormalSquare square;
	private NormalSquare s2;
	private static Dimension d;
	private static Dimension d2;
	private Room<Square> v;
	private Room<Square> c;
	private static Level<Square> du;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		d = new Dimension(10,8,10);
		d2 = new Dimension(10,9,10);
		du = new Level<Square>();
	}
	
	@Before
	public void setUp() throws Exception {
		square = new NormalSquare();
		s2 = new NormalSquare();
		c = new Room<Square>(du, square, d);
		v = new Room<Square>(du, s2, d2);
	}

	@Test
	public void testRoomDungeonSquareDimension() {
		HashMap<Dimension, Square> list = new HashMap<Dimension, Square>();
		list.put(d, square);
		assertEquals(list,c.getPositions());
		assertEquals(du,c.getDungeon());
	}

	@Test
	public void testRoomDungeonMapOfDimensionSquare() {
		HashMap<Dimension, Square> list = new HashMap<Dimension, Square>();
		list.put(d, square);
		Room<Square> q = new Room<Square>(du,list);
		assertEquals(du,q.getDungeon());
		assertEquals(list,q.getPositions());
	}

	@Test
	public void testGetAllSquares() {
		assertEquals(1,c.getAllSquares().size());
		v.mergeWith(c);
		assertEquals(2,v.getAllSquares().size());
	}

	@Test
	public void testGetAllDimensions() {
		assertEquals(1,c.getAllDimensions().size());
		v.mergeWith(c);
		assertEquals(2,v.getAllDimensions().size());
	}

	@Test
	public void testGetNumberOfSquares() {
		assertEquals(1,c.getNumberOfSquares());
		v.mergeWith(c);
		assertEquals(2,v.getNumberOfSquares());
	}

	@Test
	public void testGetSquareAt() {
		assertEquals(square,c.getSquareAt(d));
		assertEquals(null,c.getSquareAt(new Dimension(50,29,30)));
	}

	@Test
	public void testRemoveSquareAt() {
		v.mergeWith(c);
		v.removeSquareAt(d2);
		assertEquals(1,v.getNumberOfSquares());
		assertEquals(null,v.getSquareAt(d2));
	}

	@Test
	public void testGetTemp() {
		assertEquals(square.getTemp(),c.getTemperature().getTemperature(),0.1);
	}

	@Test
	public void testGetHumidityPercentage() {
		assertEquals(square.getHumidity(),c.getHumidity());
	}

	@Test
	public void testMergeWith() {
		v.mergeWith(c);
		assertEquals(0,c.getNumberOfSquares());
		assertEquals(2,v.getNumberOfSquares());
		
	}

	@Test
	public void testUpdateTemperatureAndHumidity() {
		v.mergeWith(c);
		square.setTemperature(300);
		square.setHumidity(new BigDecimal("80.00"));
		v.updateTemperatureAndHumidity();
		for(Dimension dimension: v.getAllDimensions()){
			assertEquals(150,v.getPositions().get(dimension).getTemp(),0.1);
			assertEquals(new BigDecimal("40.00"),v.getPositions().get(dimension).getHumidity());
		}
	}

	@Test
	public void testGetNeighbourSquares() {
		v.mergeWith(c);
		assertEquals(2,v.getNeighbourSquares(d).size());
	}

//	@Test
//	public void testFill() {
//		du.getRooms().add(v);
//		assertEquals(1, v.getDungeon().getRooms().size());
//		assertFalse(v.getAllSquares().get(0).hasBorder(Direction.CEILING));
//		assertTrue(v.getAllSquares().get(0).hasBorder(Direction.FLOOR));
//		v.fill(8, d2, Direction.CEILING);
//		assertEquals(9, v.getNumberOfSquares());
//	}

	@Test
	public void testGetNeighbourPosition() {
		v.mergeWith(c);
		assertEquals(d2,v.getNeighbourPosition(d));
	}

}